package Dao.impl;/*
 *徐韬
 *2021/10/9
 *9:26
 */

import Dao.UserDao;
import Util.DruidUtil;
import entity.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoimpl implements UserDao {
    QueryRunner queryRunner =new QueryRunner();
    @Override
    public User select(String uAccount) {

        try {
            return queryRunner.query(DruidUtil.getConnection(),"select * from user where uAccount = ?",new BeanHandler<>(User.class),uAccount);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+"在查询用户时出现异常");
        }
    }

    @Override
    public int update(String newPwd, String uAccount) {
        try {
            return queryRunner.update(DruidUtil.getConnection(),"update user set uPassword=? where uAccount = ?",newPwd,uAccount);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+"在修改密码时出现异常");
        }
    }
}
